package com.soa.zuul.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.soa.zuul.filter.AccessSuccessFilter;
import com.soa.zuul.filter.AppAuthFilter;
import com.soa.zuul.filter.AppLimitFilter;
import com.soa.zuul.filter.ErrorFilter;
import com.soa.zuul.filter.RequestUrlParamFilter;
import com.soa.zuul.filter.UrlAuthFilter;
import com.soa.zuul.filter.UrlLimitFilter;
import com.soa.zuul.filter.WhiteBlackListFilter;
import com.soa.zuul.service.AppLimitService;
import com.soa.zuul.service.FeignLogService;
import com.soa.zuul.service.GatewayHttpApiService;
import com.soa.zuul.service.GatewayServiceService;
import com.soa.zuul.service.UrlLimitService;
import com.soa.zuul.service.UserAuthService;

/**
 * Created by zx on 2018/10/10.
 */
@Configuration
public class CustomZuulConfig {

    @Autowired
    ZuulProperties zuulProperties;
    @Autowired
    ServerProperties server;
    @Autowired
    GatewayHttpApiService gatewayHttpApiService;
    @Autowired
    GatewayServiceService gatewayServiceService;
    @Autowired
    UserAuthService userAuthService;
    @Autowired
    UrlLimitService urlLimitService;
    @Autowired
    AppLimitService appLimitService;
    @Autowired
    FeignLogService feignLogService;
    @Bean
    public CustomRouteLocator routeLocator() {
        CustomRouteLocator routeLocator = new CustomRouteLocator(this.server.getServletPrefix(), this.zuulProperties);
        routeLocator.setJdbcTemplate(gatewayHttpApiService);
        return routeLocator;
    }
    
    @Bean
    public RequestUrlParamFilter requestUrlParamFilter(){
    	return new RequestUrlParamFilter(gatewayHttpApiService,gatewayServiceService,userAuthService,feignLogService);
    }
    @Bean
    public UrlAuthFilter urlAuthFilter(){
    	return new UrlAuthFilter(userAuthService,feignLogService);
    }
    @Bean
    public UrlLimitFilter urlLimitFilter(){
    	return new UrlLimitFilter(urlLimitService,feignLogService);
    }
    
    @Bean
    public AppAuthFilter appAuthFilter(){
    	return new AppAuthFilter(userAuthService,feignLogService);
    }
    @Bean
    public AppLimitFilter appLimitFilter(){
    	return new AppLimitFilter(appLimitService,feignLogService);
    }
    
	@Bean
	public WhiteBlackListFilter whiteBlackListFilter() {  
	      return new WhiteBlackListFilter(feignLogService);  
	}
	@Bean
	public AccessSuccessFilter accessSuccessFilter() {  
	      return new AccessSuccessFilter(feignLogService);  
	}
	@Bean
	public ErrorFilter errorFilter() {  
	      return new ErrorFilter(feignLogService);  
	}
}
